import request from '@/utils/request'

import * as Types from './types'
import {ArticlePageResp} from '../article/types'
import {PaginatedData} from "@/api/common";

// 密码登录
export async function doLogin(req: Types.PasswordLoginReq): Promise<Types.UserLoginResp> {
    return request.post('/user/doLogin', req)
}

//退出登录
export async function doLogout(): Promise<void> {
    return request.get('/user/logout')
}

// 密码注册
export async function doRegister(req: Types.PasswordRegisterReq): Promise<Object> {
    return request.post('/user/register', req)
}

// 是否已登录
export async function checkLogin(): Promise<Types.UserLoginResp> {
    return request.get('/user/login/check')
}

//用户明细信息
export async function getDetail(userId: number): Promise<Types.UserDetailResp> {
    return request.get('/user/detail?userId=' + userId)
}

//用户文章评论
export async function pageArticleComment(req: Types.UserArticleCommentPageReq): Promise<PaginatedData<Types.UserArticleCommentPageResp>> {
    return request.post('/user/article/comment/page', req)
}

//用户收藏文章
export async function pageArticleStar(req: Types.UserArticleStarPageReq): Promise<PaginatedData<ArticlePageResp>> {
    return request.post('/user/article/star/page', req)
}

//更新用户信息
export async function updateUserInfo(req: Types.UserInfoUpdateReq): Promise<void> {
    return request.post('/user/update', req)
}

//分页查询用户粉丝
export async function pageUserFollowed(req: Types.UserFollowedPageReq): Promise<PaginatedData<Types.UserFollowedPageResp>> {
    return request.post('/user/followed/page', req)
}

//分页查询用户关注列表
export async function pageUserFollow(req: Types.UserFollowPageReq): Promise<PaginatedData<Types.UserFollowedPageResp>> {
    return request.post('/user/follow/page', req)
}

//关注/取消关注
export async function userFollow(req: Types.UserFollowReq): Promise<void> {
    return request.post('/user/follow', req)
}
//修改密码
export async function updatePwd(req: Types.UserPwdUpdateReq): Promise<void> {
    return request.post('/user/pwd/update', req)
}